
		set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER TRIGGER [HeadingTemplateOnUpdate] 
   ON  [dbo].[HeadingTemplate] 
   AFTER Update
AS 
	declare @tablePrimaryKey HeadingCodeType
	declare @UpdateBy nvarchar(50)
	declare @UpdateIP nvarchar(50)
	declare @UpdateDate datetime
	
	select @tablePrimaryKey = [HeadingCode] from inserted
	select @UpdateBy = [UpdateBy] from inserted
	select @UpdateIP = [UpdateIP] from inserted
	select @UpdateDate = [UpdateDate] from inserted
	

if (update([HeadingCode]))
 begin
  declare @NewHeadingCode HeadingCodeType
  declare @OldHeadingCode HeadingCodeType

  select @OldHeadingCode = [HeadingCode] from Deleted
  select @NewHeadingCode = [HeadingCode] from inserted
if( @OldHeadingCode != @NewHeadingCode)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('HeadingCode','HeadingTemplate',@tablePrimaryKey,@NewHeadingCode,@OldHeadingCode,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([HeadingName]))
 begin
  declare @NewHeadingName LongNameType
  declare @OldHeadingName LongNameType

  select @OldHeadingName = [HeadingName] from Deleted
  select @NewHeadingName = [HeadingName] from inserted
if( @OldHeadingName != @NewHeadingName)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('HeadingName','HeadingTemplate',@tablePrimaryKey,@NewHeadingName,@OldHeadingName,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([HeadingNameChinese]))
 begin
  declare @NewHeadingNameChinese LongNameType
  declare @OldHeadingNameChinese LongNameType

  select @OldHeadingNameChinese = [HeadingNameChinese] from Deleted
  select @NewHeadingNameChinese = [HeadingNameChinese] from inserted
if( @OldHeadingNameChinese != @NewHeadingNameChinese)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('HeadingNameChinese','HeadingTemplate',@tablePrimaryKey,@NewHeadingNameChinese,@OldHeadingNameChinese,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([HeadingDescription]))
 begin
  declare @NewHeadingDescription DescriptionType
  declare @OldHeadingDescription DescriptionType

  select @OldHeadingDescription = [HeadingDescription] from Deleted
  select @NewHeadingDescription = [HeadingDescription] from inserted
if( @OldHeadingDescription != @NewHeadingDescription)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('HeadingDescription','HeadingTemplate',@tablePrimaryKey,@NewHeadingDescription,@OldHeadingDescription,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([Section]))
 begin
  declare @NewSection SequenceType
  declare @OldSection SequenceType

  select @OldSection = [Section] from Deleted
  select @NewSection = [Section] from inserted
if( @OldSection != @NewSection)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('Section','HeadingTemplate',@tablePrimaryKey,@NewSection,@OldSection,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([OwnerGroupID]))
 begin
  declare @NewOwnerGroupID GroupIDType
  declare @OldOwnerGroupID GroupIDType

  select @OldOwnerGroupID = [OwnerGroupID] from Deleted
  select @NewOwnerGroupID = [OwnerGroupID] from inserted
if( @OldOwnerGroupID != @NewOwnerGroupID)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('OwnerGroupID','HeadingTemplate',@tablePrimaryKey,@NewOwnerGroupID,@OldOwnerGroupID,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([IsDelete]))
 begin
  declare @NewIsDelete int
  declare @OldIsDelete int

  select @OldIsDelete = [IsDelete] from Deleted
  select @NewIsDelete = [IsDelete] from inserted
if( @OldIsDelete != @NewIsDelete)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('IsDelete','HeadingTemplate',@tablePrimaryKey,@NewIsDelete,@OldIsDelete,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

